package com.huike.web.controller.clues;

import com.huike.clues.domain.TbCourse;
import com.huike.clues.service.TbCourseService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/clues/course")
@Api(tags = "课程管理相关接口")
public class TbCourseController extends BaseController {
    @Resource
    private TbCourseService tbCourseService;


    /**
     * 查询课程管理列表接口
     *
     * @param tbCourse
     * @return
     */
    @ApiOperation("查询课程管理列表接口")
    @GetMapping("/list")
    public TableDataInfo list(TbCourse tbCourse) {
        log.info("查询课程管理列表接口:{}", tbCourse);
        List<TbCourse> list = tbCourseService.selectTbCourseList(tbCourse);
        return getDataTable(list);
    }

    /**
     * 新增课程接口
     */
    @ApiOperation("新增课程接口")
    @PostMapping
    public AjaxResult insertTbCourse(@RequestBody TbCourse tbCourse) {
        log.info("新增课程接口:{}", tbCourse);
        tbCourseService.insertTbCourse(tbCourse);
        return AjaxResult.success("操作成功");
    }

    /**
     * 通过Id查询课程接口
     */
    @ApiOperation("新增课程接口")
    @GetMapping("/{id}")
    public AjaxResult findByTbCourse(@PathVariable Long id) {
        log.info("通过Id查询课程接口:{}", id);
        TbCourse tbCourse = tbCourseService.findByTbCourse(id);
        return new AjaxResult(200, "操作成功", tbCourse);
    }

    /**
     * 修改课程接口
     */
    @ApiOperation("修改课程接口")
    @PutMapping
    public AjaxResult updateTbCourse(@RequestBody TbCourse tbCourse) {
        log.info("修改课程接口:{}", tbCourse);
        tbCourseService.updateTbCourse(tbCourse);
        return AjaxResult.success("操作成功");
    }

    /**
     * 通过Id删除课程接口
     */
    @ApiOperation("通过Id删除课程接口")
    @DeleteMapping("/{ids}")
    public AjaxResult deleteByTbCourse(@PathVariable List<Long> ids) {
        log.info("通过Id删除课程接口:{}", ids);
        tbCourseService.deleteByTbCourse(ids);
        return AjaxResult.success("操作成功");
    }


}
